package cn.kgm.autoCancel.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2023-9-14 16:41
 * @Description: cn.kgm.autoCancel.quartz.QuartzActuator
 */
public class QuartzActuator implements Job {

    public static void main(String[] args) throws SchedulerException {
        // 创建任务
        JobDetail jobDetail = JobBuilder.newJob(QuartzActuator.class)
                .withIdentity("job", "group").build();
        // 创建任务的执行方式
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger", "group3")
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(2)
                        .repeatForever())
                .build();
        // 通过抽象工厂，获取一个循环器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        // 给循环器赋值
        scheduler.scheduleJob(jobDetail, trigger);
        // 循环器按照执行格式执行代码
        scheduler.start();
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("我执行喽~");
    }
}
